package wechat

import (
	"gitee.com/edodo/flysdk/api"
)

// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/clearQuota.html
func (wcApi *wcMpApi) ClearQuota(config *api.MpConfig, at *api.AccessToken) (e error) {
	output := new(WxError)
	if e = api.PostJson(CLEAR_QUOTA_URL, map[string]string{
		"access_token": at.AccessToken,
	}, map[string]any{
		"appid": config.AppId,
	}, output); e != nil {
		//glog.Errorf("clear api quota failed: %v", e)
		return
	}
	return
}

/*
https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getApiQuota.html

	@param cgi_path api的请求地址，例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ，也不要漏了"/",否则都会76003的报错
*/
func (wcApi *wcMpApi) GetApiQuota(at *api.AccessToken, cgi_path string) (quota api.Quota, e error) {
	output := new(WxQuota)
	if e = api.PostJson(GET_API_QUOTA_URL, map[string]string{
		"access_token": at.AccessToken,
	}, map[string]any{
		"cgi_path": cgi_path,
	}, output); e != nil {
		//glog.Errorf("Get api quota failed: %v", e)
		return
	}
	quota = output.Quota
	return
}
